home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
surfdemo
/
surfthresh.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-10
|
12KB
|
358 lines
#ifndef lint
static char SccsId[]= "@(#)surfthresh.c V1.10 3/17/95";
#endif
/*------------------------------------------------------------------
| file name -- surfthresh.c
|
| Functions related to changing the color thresholds for the graph's.
| The threshold control drawport is drawn over the graph, when this drawport
| is active, all other picks are ignored. The user must select OK or
| CANCEL to remove the drawport.
|
| functions Description
| --------- -----------
| InitThreshControls Initializes the input objects for chaning thresholds
| DrawThreshControls Draws the threshold control drawport
|
| HandleThreshControls Handles all events inside the control drawport
| EchoThreshBoxes Echos the threshold choice in the threshold box
|
| change_color Changes the colors in the selection boxes
| init_slider Initialize the slider for changing the threshold
|
|-----------------------------------------------------------------*/
#include "std.h"
#include "dvstd.h"
#include "dvtools.h"
#include "VOstd.h"
#include "dvGR.h"
#include "Tfundecl.h"
#include "surfdata.h"
#include "dvinteract.h"
#include "VOfundecl.h"
#include "VUerfundecl.h"
#include "VPfundecl.h"
#include "surffundecl.h"
/* Declare the various flags to be passed through the event handler */
#define OK_CANCEL_EVENT 0
#define PICK_EVENT 1
#define CANCEL_VALUE -1
#define NO_INDEX -1
#define OK_CANCEL_MENU "OkCancelMenu"
#define SLIDER_NAME "ThreshSlider"
#define CHOICE_BOX_NAME "Choice"
/*------------------------------------------------------------------
| Local declarations
|-----------------------------------------------------------------*/
LOCAL CHAR *ColorName[]=
{
"Color1",
"Color2",
"Color3",
"Color4",
};
LOCAL OBJECT ThreshSlider;
LOCAL OBJECT InitForegroundColor;
LOCAL OBJECT InitBackgroundColor;
LOCAL INT
ThreshMenuValue, CurrentThreshIndex;
LOCAL FLOAT
ThreshSliderValue, SavedThreshValue[NUM_THRESHOLDS];
LOCAL VARDESC SliderVdp;
/***************** Begin Function Declarations *************/
LOCAL void EchoThreshBoxes V_P_((OBJECT input, int origin, int state, float *value, ADDRESS vdp, RECTANGLE *vp, ADDRESS *args));
LOCAL ADDRESS change_color V_P_((OBJECT obj, char *name, ADDRESS args));
LOCAL void init_slider V_P_((int index));
/***************** End Function Declarations *************/
/*------------------------------------------------------------------
|
| InitThreshControls
| This functions sets up the service and echo functions for
| the changing the thresholds of the graph. Named areas are used
| to determine which threshold to change. A slider input object
| is used to get the new threhsold. A menu is used to know when to
|
*/
void InitThreshControls
V_P_ ((void))
{
OBJECT menu, it;
VARDESC vdp;
ATTRIBUTES atts;
/* Set flags */
ThreshActive = NO;
/* Access the Embedded OK/CANCEL Menu */
menu = VOdrGetNamedObject (ThreshDrawing, OK_CANCEL_MENU);
vdp = GetVdp (menu);
(VOID) TvdPutBuffer (vdp, (ADDRESS) & ThreshMenuValue);
VPvdtype (vdp, V_I_TYPE);
(VOID) VUerServiceResultPost ((OBJECT) 1, HandleThreshControls,
(ADDRESS) NULL, 0,
menu, INPUT_DONE, OK_CANCEL_EVENT);
/* Access the embedded slider */
ThreshSlider = VOdrGetNamedObject (ThreshDrawing, SLIDER_NAME);
SliderVdp = GetVdp (ThreshSlider);
(VOID) TvdPutBuffer (SliderVdp, (ADDRESS) & ThreshSliderValue);
/* Set up Echo Function for the slider */
it = VOinTechnique (ThreshSlider, DONT_SET_THE_VALUE);
VOitPutEchoFunction (it, (VOITECHOFUNPTR)EchoThreshBoxes, (ADDRESS) NULL, 0);
/* Save the slider's color, it's used when we draw the ThreshControls */
VOobAtGet (ThreshSlider, &atts);
InitForegroundColor = atts.foreground_color;
InitBackgroundColor = atts.background_color;
}
/*------------------------------------------------------------------
|
| DrawThreshControls
| This functions draws the threshold control drawport. Before we
| draw the controls, we save the old threshold in case the user
| CANCELs the changes. We also post a service function to
| capture all picks. This makes the user interact only with the
| control drawport.
*/
void DrawThreshControls
V_P_ ((void))
{
INT i;
ATTRIBUTES atts;
/* Make Changes to the threhold boxes */
for (i = 0; i < NUM_COLORS; i++)
(VOID) TdrForEachNamedObject (ThreshDrawing, change_color, (ADDRESS) i);
/* Save the old values in case of a CANCEL */
SetThresholds (); /* found in surfthresh.c */
for (i = 0; i < NUM_THRESHOLDS; i++)
SavedThreshValue[i] = ThreshValue[i];
/* Initialize event handling for the threshold controls...
| Block out picks outside the drawport area, that way the user
| can't interact with the other contorls. This routine gets called
| after other requested are posted, so this acts as a mask.
|
| The HandleThreshControls will deal with erasing the control drawport
| and clearing the posted event requests.
*/
(VOID) VUerRectEdgePost ((OBJECT) THRESHOLD_COMMAND,
HandleThreshControls, (ADDRESS) NULL, 0,
(RECTANGLE *) NULL, (DV_BOOL) V_OUTSIDE, "", PICK_EVENT);
/* Initialize the slider for the default case */
VPvd_drange (SliderVdp, (FLOAT) - 1, (FLOAT) 1);
VOobAtGet (ThreshSlider, &atts);
atts.foreground_color = InitForegroundColor;
atts.background_color = InitBackgroundColor;
VOobAtSet (ThreshSlider, &atts);
/* Draw the Threshold Control Area */
(VOID) TdpDraw (ThreshDrawport);
ThreshActive = YES;
/* Make the slider inactive until the user selects a threshold */
(VOID) VOinState (ThreshSlider, INACTIVE);
}
/*------------------------------------------------------------------
|
| EchoThreshBoxes
| This functions echos the threshold slider choice in the threshold
| if the user is currently changing a threshold.
*/
/* ARGSUSED */
LOCAL void
EchoThreshBoxes (input, origin, state, value, vdp, vp, args)
OBJECT input;
int origin;
int state;
float *value;
ADDRESS vdp;
RECTANGLE *vp;
ADDRESS *args;
{
FLOAT factor;
INT i;
if (origin == TAKE_INPUT)
{
/* Set the Threshold Value to the slider value */
ThreshValue[CurrentThreshIndex] = ThreshSliderValue;
/* Determine the new values */
for (i = 0; i < NUM_THRESHOLDS; i++)
{
factor = (ThreshValue[i] - Formula.zmin) /
(Formula.zmax - Formula.zmin);
ThreshTable[i].upperlimit = (SHORT) (32767 * factor);
}
/* Draw the threshold box */
DrawThreshRect (ThreshEchoArea);
/* If we are done, quit echoing */
if (state == INPUT_DONE)
{
/* Make the slider inactive until the user selects a threshold */
(VOID) VOinState (ThreshSlider, INACTIVE);
CurrentThreshIndex = NO_INDEX;
}
}
}
/*------------------------------------------------------------------
|
| HandleThreshControls
| This functions handles all picks inside the control drawport.
|
| If the user selected inside the OK/CANCEL menu, if needed we
| restore the old thresholds and then erase the control and redraw
| the graph. We also clear the service function associated with
| masking all picks.
|
| If the user made a pick inside the control drawport, we see
| if they have selected a new threshold to change.
*/
/* ARGSUSED */
int
HandleThreshControls (client, request, event_type, loc, args)
OBJECT client; /* Input object initiating the call */
EVENT_REQUEST request; /* Event request that triggered the call */
int event_type; /* Label from the service result posting */
OBJECT loc; /* Current location object */
ADDRESS args; /* Arguments from the service result posting */
{
FLOAT factor; /* Used to compute the normalized threshold value */
INT i;
if (event_type == OK_CANCEL_EVENT)
{
/* Determine if we use the old or new threshold values */
if (ThreshMenuValue == CANCEL_VALUE)
{
for (i = 0; i < NUM_THRESHOLDS; i++)
ThreshValue[i] = SavedThreshValue[i];
}
/* Compute the new normalized threshold value */
for (i = 0; i < NUM_THRESHOLDS; i++)
{
factor = (ThreshValue[i] - Formula.zmin) /
(Formula.zmax - Formula.zmin);
ThreshTable[i].upperlimit = (SHORT) (32767 * factor);
}
DrawThreshRect (ThreshEchoArea);
/* Remove Threshold Control Drawport and restore the graph */
CurrentThreshIndex = NO_INDEX;
(VOID) TdpErase (ThreshDrawport);
ThreshActive = NO;
DoPlot ();
/* Clear the event requests related */
VUerClearAll ((OBJECT) THRESHOLD_COMMAND);
}
else
/* Must be a pick inside the control area */
{
OBJECT obj;
CHAR *name;
obj = TloGetSelectedObject (loc);
if (obj)
{
name = TdrGetObjectName (ThreshDrawing, obj);
if (name && S_STRNCMP (name, "Choice", 6) == 0)
{
CurrentThreshIndex = (INT) S_ATOI (&name[6]) - 1;
init_slider (CurrentThreshIndex);
}
}
}
return DV_SUCCESS;
}
/*------------------------------------------------------------------
|
| change_color
| This functions changes the colors associated with boxes for
| selecting which threshold to change.
*/
LOCAL ADDRESS
change_color (obj, name, args)
OBJECT obj;
char *name;
ADDRESS args;
{
INT index, color_index;
ATTRIBUTES atts;
index = (INT) args;
if (strcmp (name, ColorName[index]) == 0)
{
VOobAtGet (obj, &atts);
color_index = ThreshTable[index].threshcolor.color_index;
atts.foreground_color = VOcoCreate (COLOR_INDEX, (LONG) color_index,
(LONG) 0, (LONG) 0);
VOobAtSet (obj, &atts);
}
return NULL;
}
/*------------------------------------------------------------------
|
| init_slider
| This functions changes the color and range of the slider to
| match the threshold the user is changing or the default.
*/
LOCAL void
init_slider (index)
int index;
{
DOUBLE lower, upper;
ATTRIBUTES atts;
/* Set the initial value */
ThreshSliderValue = ThreshValue[index];
/* Determine the range based on which threshold */
if (index == 0)
lower = Formula.zmin;
else
lower = ThreshValue[index - 1];
if (index == 2)
upper = Formula.zmax;
else
upper = ThreshValue[index + 1];
VPvd_drange (SliderVdp, lower, upper);
/* Change the colors of the sliders, based on the threshold values */
VOobAtGet (ThreshSlider, &atts);
atts.foreground_color =
VOcoCreate ('i', ThreshTable[index].threshcolor.color_index);
atts.background_color =
VOcoCreate ('i', ThreshTable[index + 1].threshcolor.color_index);
VOobAtSet (ThreshSlider, &atts);
(VOID) TdpDrawObject (ThreshDrawport, ThreshSlider);
(VOID) VOinState (ThreshSlider, ACTIVE);
}